package com.treeroot.stack;

import java.util.Scanner;

public class ArrayStackDemo {
    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack(4);
        char key;
        //控制是否退出菜单
        boolean loop = true;
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.println("s.show:显示栈");
            System.out.println("e.exit:退出程序");
            System.out.println("h.push:入栈");
            System.out.println("p.pop:出栈");
            System.out.println("请输入你的选择");
            key = sc.next().charAt(0);//接收一个字符
            switch (key){
                case 's':
                    arrayStack.list();
                    break;
                case 'h':
                    System.out.println("请输入一个数");
                    int value = sc.nextInt();
                    arrayStack.push(value);
                    break;
                case 'p':
                    try {
                        int res = arrayStack.pop();
                        System.out.printf("出栈的数据是%d\n",res);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    sc.close();
                    loop = false;
                    break;
                default:
                    break;
            }
            if(!loop){
                break;
            }
        }


    }
}
